//用户信息的仓库
export default{
	state:{
		//登录状态
		loginStatus:false,
		//token
		token:null,
		//用户信息：头像|昵称...
		userInfo:{},
	},
	mutations:{
		// 检测用户是否是登录状态
		initUser( state ){
			
			let userInfo = JSON.parse( localStorage.getItem('userInfo')  );
			if( userInfo  ){
				state.loginStatus = true;
				state.token = userInfo.token;
				state.userInfo = userInfo;
			}
			
		},
		login( state  , user  ){
			state.loginStatus = true;
			state.token = user.token;
			state.userInfo = user;
			//持久化存储==》本地存储
			localStorage.setItem('userInfo',JSON.stringify(  user  ) );
		},
		//退出登录
		loginOut( state ){
			
			state.loginStatus = false;
			state.token = null;
			state.userInfo = {};
			localStorage.removeItem('userInfo');
			
		}
	}
}
